<?php
defined('BASEPATH') OR exit('No direct script access allowed');

class Api extends BaseController {

	public function __construct() {
        parent::__construct();
    }

    // 删除又拍云老的视频文件
    public function delete_upyun_file(){
        $fileName = str_replace(UP_VIDEO_NEW_NAME, "", $this->post['path'][0]);
        // 加载又拍云sdk
        require_once('vendor/autoload.php');
        // 初始化又拍云接口
        $config = new Upyun\Config(UP_BUCKET, UP_USERNAME, UP_PASSWORD);
        $upyun = new Upyun\Upyun($config);

        sleep(240);
        $upyun->delete($fileName);
    }

    // 批量重置学生账号
    public function reset_student_password($schoolId) {
        // 加载库
        $this->load->model('schoolModel');
        $schoolInfo = $this->schoolModel->get_school_info($schoolId);
        if(!$schoolInfo) show_error("参数错误");

        // 批量重置学生密码
        $studentParams['schoolId'] = $schoolInfo['id'];
        $studentList = $this->schoolModel->get_student_list($studentParams);
        foreach($studentList as $student) {
            $updateData['password'] = password_hash(123456, PASSWORD_DEFAULT);
            $this->db->update(SchoolModel::$schoolStudentTable, $updateData, "id='{$student['id']}'");
        }
        exit(json("ok", true));
    }
}
